package com.org.platform.support.conponents.delqueue;

import com.org.platform.utils.LocalDateUtil;
import java.time.LocalDateTime;
import java.util.concurrent.DelayQueue;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Consumer implements Runnable {

  // 延时队列 ,消费者从其中获取消息进行消费

  private DelayQueue<Message> queue;

  public Consumer(DelayQueue<Message> queue) {
    this.queue = queue;
  }

  @Override
  public void run() {
    while (true) {
      try {
        Message take = queue.take();
        String nowTime = LocalDateUtil.localDateTimeFormat(LocalDateTime.now(), LocalDateUtil.FORMAT_PATTERN1);
        log.info("时间:" + nowTime + ",消费消息id：" + take.getId() + ",消息体：" + take.getBody());
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
}
